package com.miukoo.aikao.core.types;

import com.miukoo.aikao.core.dtos.QuestionAnswerDto;
import com.miukoo.aikao.core.dtos.QuestionDetailDto;
import com.miukoo.aikao.core.exceptions.ApiException;
import com.miukoo.aikao.core.pojos.QuestionChooseDto;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 问题类型的实现接口
 * @Author miukoo<miukoo@126.com>
 * @Date 2020/11/25  
 * @Version 1.0
 */
public interface TypeInterface {

    /**
     * 检查答案内容是否空
     * @param answerList
     * @param no
     * @return
     */
    default int checkAnswerNull(List<QuestionAnswerDto> answerList, String no){
        int trueCount = 0;
        for (QuestionAnswerDto a : answerList) {
            if (a.getIsRight() == null) {
                throw new ApiException(1, no + "必须定义选项是否正确项！");
            }
            if (StringUtils.isEmpty(a.getContent())) {
                throw new ApiException(1, no + "选项内容不为空！");
            }
            if (a.getIsRight()) {
                trueCount += 1;
            }
        }
        return trueCount;
    }

    /**
     * 后台保存问题时，对类型的检查函数
     * @param dto
     */
    public void saveCkeck(QuestionDetailDto dto);

    /**
     * 后台保存问题时，对类型的检查函数
     * @param repoId
     * @param type
     * @param level
     * @param size
     * @param answerCount
     * @param score
     * @return
     */
    public List<QuestionChooseDto> chooseQuestion(Long repoId, Short type, Short level, Short size, Short answerCount, Short score) ;

}
